package studyguide.ch09.graphics;

import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class GraphicsCanvasG extends Canvas {

	protected void paint(Graphics g) {
		// Clear screen
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, getWidth(), getHeight());
		
		// Vertical distance between objects:
		int x = getWidth() / 2;
		int yStep = getHeight() / 3;
		int y = 0;
		
		g.setColor(0); // Black

		Font font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_ITALIC, Font.SIZE_LARGE);
		g.setFont(font);
		
		y += yStep;
		g.drawString("Italic font sample", x, y, Graphics.HCENTER|Graphics.BASELINE);
		
		y += yStep;
		Image image;
		try {
			image = Image.createImage("/icons/iconSG.png");
		} catch (IOException e) {
			throw new RuntimeException("Error loading image:" + e.getMessage());
		}
		g.drawImage(image, x, y, Graphics.HCENTER|Graphics.VCENTER);
	}

}
